/**
 * 
 */
package net.homelinux.ajay.net.ondisk.view.client;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author ajay
 *
 */
public abstract class NamedCommand implements Command {
  private String name;
  private Widget widget;
  private Image image;

  public NamedCommand(String name, Image image){
    this.name = name;
    this.image = image;
    widget = makeWidget();
  }
  
  private Widget makeWidget() {
    Label ret = new Label(name);
    ret.addClickListener(new ClickListener(){

      public void onClick(Widget sender) {
        NamedCommandHandler.getInstance().processCommand(NamedCommand.this);
      }
      
    });
    
    return ret;
  }

  public String getName(){
    return name;
  }

  public Widget getWidget() {
    return widget;
  }
  
  public Image getImage() {
    return image;
  }

  public MenuItem getMenuItem() {
    String menuhtml = getName();
    if(image !=null){
      menuhtml = "<img src='"+image.getUrl()+"' width='"+image.getOffsetWidth()+"' height='"+image.getOffsetHeight()+"' alt='"+image.getTitle()+"'/>" + menuhtml;
    }
    MenuItem item = new MenuItem(menuhtml, true, this);
    return item;
  }
}
